package com.ming.controller;

import com.ming.po.Orders;
import com.ming.po.ResponseBean;
import com.ming.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/OrdersController")
public class OrdersController {

    @Autowired
    private OrdersService os;

    @PostMapping("/createOrders")
    public ResponseBean<Integer> createOrders(Orders orders){
        // 控制层需要对数据格式进行过滤,以保证服务层和Dao层的输入数据没有问题

        // 返回的是订单主键
        return os.createOrders(orders);
    }

    @GetMapping("/getOrdersById")
    public ResponseBean<Orders> getOrdersById(Integer orderId){
        return os.getOrderById(orderId);
    }

    @GetMapping("/listOrdersByUserId")
    public ResponseBean<List<Orders>> listOrdersByUserId(String userId){
        return os.listOrdersByUserId(userId);
    }

    @GetMapping("/listOrdersDetailByUserId")
    public ResponseBean<List<Orders>> listOrdersDetailByUserId(String userId){
        return os.listOrdersDetailByUserId(userId);
    }
}
